package com.xbts.web.controller.party;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.system.domain.PartyArea;
import com.xbts.system.service.IPartyAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 片区管理Controller
 *
 * @author xbts
 * @date 2023-06-12
 */
@Api(tags = "片区管理")
@RestController
@RequestMapping("/party/area")
public class PartyAreaController extends BaseController {

    @Autowired
    private IPartyAreaService partyAreaService;

    /**
     * 查询片区管理列表
     */
    @ApiOperation("查询片区管理列表")
    @PreAuthorize("@ss.hasPermi('party:area:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PartyArea partyArea) {
        startPage(partyArea);
        List<PartyArea> list = partyAreaService.selectPartyAreaList(partyArea);
        return getDataTable(list);
    }

    /**
     * 导出片区管理列表
     */
    @ApiOperation("导出片区管理列表")
    @PreAuthorize("@ss.hasPermi('party:area:export')")
    @Log(title = "片区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody PartyArea partyArea) {
        List<PartyArea> list = partyAreaService.selectPartyAreaList(partyArea);
        ExcelUtil<PartyArea> util = new ExcelUtil<PartyArea>(PartyArea.class);
        util.exportExcel(response, list, "片区管理数据");
    }

    /**
     * 获取片区管理详细信息
     */
    @ApiOperation("获取片区管理详细信息")
    @ApiImplicitParam(name = "areaId", value = "片区管理ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('party:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") String areaId) {
        return success(partyAreaService.selectPartyAreaByAreaId(areaId));
    }

    /**
     * 新增片区管理
     */
    @ApiOperation("新增片区管理")
    @PreAuthorize("@ss.hasPermi('party:area:add')")
    @Log(title = "片区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PartyArea partyArea) {
        return toAjax(partyAreaService.insertPartyArea(partyArea));
    }

    /**
     * 修改片区管理
     */
    @ApiOperation("修改片区管理")
    @PreAuthorize("@ss.hasPermi('party:area:edit')")
    @Log(title = "片区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PartyArea partyArea) {
        return toAjax(partyAreaService.updatePartyArea(partyArea));
    }

    /**
     * 删除片区管理
     */
    @ApiOperation("删除片区管理")
    @ApiImplicitParam(name = "areaIds", value = "片区管理ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('party:area:remove')")
    @Log(title = "片区管理", businessType = BusinessType.DELETE)
    @PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> areaIds) {
        return toAjax(partyAreaService.deletePartyAreaByAreaIds(areaIds));
    }
}
